#!/usr/bin/env python  
# -*- coding: utf-8 -*-  
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
import smtplib
import sys
type = sys.getfilesystemencoding() 
reload(sys)  
sys.setdefaultencoding('utf8')

sender = 'ljp@addcn.com'
passwd = 'Fj0491062'
receivers = ['ljp@addcn.com']
 
emails = [elem.strip().split(',') for elem in receivers]
msg = MIMEMultipart()
msg['Subject'] = "my_subject_jinping_liu_smart"
msg['From'] = sender
msg['To'] = ','.join(receivers)
 
msg.preamble = 'Multipart massage.\n'
part = MIMEText("劉金平很帥")
msg.attach(part)
 
print sys.argv[1]
part = MIMEApplication(open(str(sys.argv[1]),"rb").read())
if len(sys.argv) > 2:
    attachname = str(sys.argv[2])
else:
    attachname = str(sys.argv[1])
 
part.add_header('Content-Disposition', 'attachment', filename=attachname)
msg.attach(part)
 
smtp = smtplib.SMTP("smtp.gmail.com:587")
smtp.ehlo()
smtp.starttls()
smtp.login(sender, passwd)
 
smtp.sendmail(msg['From'], emails , msg.as_string())
print 'Send mails to',msg['To']